home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9847 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: newsfeed.internetmci.com!guardian!slip30
  2. From: genesis@forbin.com (Dances with Demons)
  3. Newsgroups: comp.lang.c++
  4. Subject: Question about visibility of local variables
  5. Date: Mon, 04 Mar 96 18:49:44 GMT
  6. Organization: The Genesis Project
  7. Message-ID: <4hfkpc$9em@guardian.forbin.com>
  8. NNTP-Posting-Host: slip30.forbin.com
  9. X-Newsreader: News Xpress Version 1.0 Beta #4
  10.  
  11. I am in the process of learning C++ which surprised me in being 
  12. as awesome as everyone kept telling me.  It is literally better
  13. than anything I ever expected.  I ran into one dark area for me
  14. in the area of automatic variables. 
  15.    It said in the book I'm studying, "Object-Oriented Programming
  16. in C++, by Robert Lafore", that when a function is executed, the
  17. and the variable is defined, it will continue to exist until the
  18. function is exited.  When this happens, the memory that the variable
  19. is freed up and is used by other variables/function calls, etc.
  20.  
  21. The question is:  When you define a variable in main(), and call another 
  22. function, or even when defining a local variable in a function that calls 
  23. another function, why are the local variables not destroyed.
  24.    I had a thought that maybe since main() called the function, it still had 
  25. control, (at least as far as variable usage went) and therefore didn't
  26. free up the memory until the function is actually completed, (End
  27. of the program), but I wasn't sure.  Could someone please verify that this is 
  28. indeed the case, or refute it and give me the real reason.
  29.  
  30. I thank you in advance, any help will be greatly appreciated.
  31. Thomas Klemensen  -  genesis@forbin.com
  32.